#include "stdafx.h"

#include "role.h"
#include "agent.h"
using namespace BAA;


Agent* BAA::Role::TargetContainsAgent( Agent * agent )
{
	return 
		(*mTargets)[agent];
}

Agent* BAA::Role::TargetContainsAgent( AgentPointerMap * agents )
{

	for(AgentPointerMap::iterator it = agents->begin();
		it != agents->end(); 
		++it)
	{
		if((*mTargets)[it->second])
		{
			return it->second;
		}
	}

	return NULL;

}

void BAA::Role::Initialize( Agent * self, AgentPointerMap* targets, float roleImportance )
{
	mSelf = self;
	mTargets = targets;
	mRoleImportance = roleImportance;

	/* INIT ANY CHILD OBJECTS */


	// INIT GOALS
	for(StringGoalMap::iterator it = mGoals.begin(); it != mGoals.end(); ++it)
		it->second->Initialize(this);

	// INIT EMOTIONS

	// INIT ACTIONS

	for(StringActionMap::iterator it = mActions.begin(); it != mActions.end(); ++it)
		it->second->Initialize(this, targets);

	// INIT VALUES
	for(ValueValueMap::iterator it = mValues.begin(); it != mValues.end(); ++it)
		it->second->Initialize(this);

}